#ifndef _STEG_BMP_H_
#define _STEG_BMP_H_
/**
 * refer:http://blog.csdn.net/o_sun_o/article/details/8351037
**/

#include <fstream>
#include <cstdlib>
#include <stdint.h>

using namespace std;

struct BITMAPFILEHEADER {
	uint16_t bfType;
	uint32_t bfSize;
	uint16_t bfReserved1;
	uint16_t bfReserved2;
	uint32_t bfOffBits;
};

struct BITMAPINFOHEADER {
	uint32_t biSize;
	uint32_t biWidth;
	uint32_t biHeight;
	uint16_t biPlanes;
	uint16_t biBitCount;
	uint32_t biCompression;
	uint32_t biSizeImage;
	uint32_t biXPelsPerMeter;
	uint32_t biYPelsPerMeter;
	uint32_t biClrUsed;
	uint32_t biClrImportant;
};

#define BMP_HEADERS_SIZE 54                        // sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) = 54
#define BMP_HIDE_EOF     '\0'

namespace riguz {
	class Bmp {
	public:
		Bmp(const char *fileName);
		~Bmp();
	public:
		int decode(const char* bmp, size_t bmpLen, char *buffer, int bufferLen);
		int encode(const char* secret, char* buffer, int bufferLen);
		BITMAPFILEHEADER getBmpFileHeader() const {
			return this->_fileHeader;
		}
		BITMAPINFOHEADER getBmpInfoHeader() const {
			return this->_infoHeader;
		}
	protected:
		bool readHeader();		
	protected:
		FILE *_bmpFile;
		long _totalStuffablechar;
	protected:
		BITMAPFILEHEADER _fileHeader;
		BITMAPINFOHEADER _infoHeader;
		long bmpTotalStuffablechar;				  //ASCII stuffable character in bitmap
	};

}
#endif
